package com.yoyoyo666.report.common;

import com.yoyoyo666.report.model.common.BaseResult;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
public class WebExceptionHandle {


    @ExceptionHandler(AuthExcepiton.class)
    public BaseResult handleAuthExcepiton(Exception e) {
        BaseResult fail = BaseResult.getFail();
        fail.setCode(401);
        return fail;
    }

    @ExceptionHandler(Exception.class)
    public BaseResult handleException(Exception e) {
        BaseResult fail = BaseResult.getFail();
        String stackTrace = ExceptionUtils.getStackTrace(e);
        fail.setMsg(stackTrace);
        e.printStackTrace();
        return fail;
    }
}